package com.ant.androiddemo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

import com.ant.androiddemo.util.ToastUtil;

public class OptionsMenuActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_options_menu);
        actionBarConfig();
    }

    public void actionBarConfig(){
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setTitle("选项菜单");
        supportActionBar.setDisplayHomeAsUpEnabled(true);

//        supportActionBar.setDisplayShowHomeEnabled(true);
//        supportActionBar.setLogo(R.drawable.ic_baseline_arrow_forward_24);
//        supportActionBar.setDisplayUseLogoEnabled(true);
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.menu_options, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        int itemId = item.getItemId();
        ToastUtil.toastShort(this,"点击了"+item.getTitle());
        ToastUtil.toastShort(this,"点击了"+R.id.menu_home);
//        switch (itemId) {
//            case R.id.menu_about:
//                ToastUtil.toastShort(this,"点击了"+item.getTitle());
//                return true;
//            case R.id.menu_help:
//                ToastUtil.toastShort(this,"点击了"+item.getTitle());
//                return true;
//            case R.id.menu_home:
//                ToastUtil.toastShort(this,"点击了"+item.getTitle());
//                return true;
//            case R.id.menu_setting:
//                ToastUtil.toastShort(this,"点击了设置");
//                return true;
//            case R.id.menu_exit:
//                ToastUtil.toastShort(this,"点击了退出");
//                return true;
//            case android.R.id.home:
////                this.finish();
//                break;
//            default:
//                break;
//        }

        return super.onOptionsItemSelected(item);
    }
}